/* 1694. 重新格式化电话号码 */
/**
 * @param {string} number
 * @return {string}
 */
var reformatNumber = function (number) {
	let digits = ''
	for (let i = 0; i < number.length; ++i) {
		const ch = number[i]
		if (ch === ' ' || ch === '-') continue
		digits += ch
	}
	let n = digits.length
	let pt = 0
	let ans = ''
	while (n > 0) {
		if (n > 4) {
			ans += digits.slice(pt, pt + 3) + '-'
			n -= 3
			pt += 3
		} else {
			if (n === 4) {
				ans +=
					digits.slice(pt, pt + 2) +
					'-' +
					digits.slice(pt + 2, pt + 4)
			} else {
				ans += digits.slice(pt)
			}
			break
		}
	}
	return ans
}
const result = reformatNumber('06-005523 01')
console.log('reformatNumber :>>', result)
